package logic

import (
	"B/renrenzhuB_srv/model/mysql"
	"context"

	"B/renrenzhuB_srv/internal/svc"
	"B/renrenzhuB_srv/renrenzhuB"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *renrenzhuB.GoodListRequest) (*renrenzhuB.GoodListResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	list := g.List(in.Status)
	var good []*renrenzhuB.GoodList
	for _, i2 := range list {
		good = append(good, &renrenzhuB.GoodList{
			Title:  i2.Title,
			Price:  float32(i2.Price),
			Cover:  i2.Cover,
			Stock:  int64(i2.Stock),
			Status: i2.Status,
			Likes:  i2.Likes,
			Type:   i2.Type,
		})
	}
	return &renrenzhuB.GoodListResponse{List: good}, nil
}
